package cn.schoolwow.util.module.query.resource.flow.walkResource.common;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;

import java.net.URL;
import java.net.URLDecoder;

public class SetUrlFileFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        URL url = (URL) flowContext.checkData("url");

        String urlFile = url.getFile();
        if(urlFile.contains("%")){
            urlFile = URLDecoder.decode(urlFile, "utf-8");
        }
        //file的几种形式
        //nested:/C:/projects/RuoYi-Vue-Plus/ruoyi-admin/target/ruoyi-admin.jar/!BOOT-INF/classes/!/initial/json/menu
        if(urlFile.contains("!")){
            urlFile = urlFile.substring(urlFile.lastIndexOf("!")+2);
        }
        flowContext.putTemporaryData("urlFile", urlFile);
    }

    @Override
    public String name() {
        return "设置url的file属性";
    }
}
